{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# \"Onion Ring Bokeh\"\n", "\n", "In the photography community, defects in the out-of-focus highlights of lenses are widely discussed. These result from mid-particular spatial frequency errors on the optical surfaces. Here, we will show an example of using prysm in a relatively extended fashion to model this. We begin, as usual, by importing some classes and other libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from prysm import NollZernike, PSF\n", "from prysm.coordinates import make_rho_phi_grid\n", "\n", "from matplotlib import pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We begin by using the `NollZernike` class to make a pupil with 25 waves fo defocus to give us a relatively uniform disk for the diffraction limited out of focus image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pupil = NollZernike(Z4=25/1.5, samples=384, dia=25, z_unit='waves') # 100 waves PV of defocus, 25mm for F/2\n", "\n", "ps = PSF.from_pupil(pupil, efl=50, Q=1)\n", "ps.plot2d(xlim=200, power=1/3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ripples are Fresnel rings and are a consequence interference very similar to the [Gibbs phenomenon](https://en.wikipedia.org/wiki/Gibbs_phenomenon). They disappear the farther out of focus you go, and can be wiped away by coarser sampling with an image sensor, or significantly polychromatic light.\n", "\n", "We used a value of Q below 2 (worse than Nyquist sampled) because the image is so out of focus, it largely lacks high spatial frequency content to be aliased, so the choice of Q has minimal consequence.\n", "\n", "What if the pupil had some ripples in it from structured errors on optical surfaces in the system?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pupil2 = pupil.copy()\n", "\n", "rho, _ = make_rho_phi_grid(samples_x=pupil.samples_x)\n", "\n", "# 15 cycles per aperture, lambda/25 RMS amplitude\n", "const = 2 * np.pi * 15\n", "phase_mod = np.sin(rho * const) * (np.sqrt(2) / 25)\n", "pupil2.phase += phase_mod\n", "\n", "ps = PSF.from_pupil(pupil2, efl=50, Q=1) \n", "ps.plot2d(xlim=200, power=1/3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ripples print through into the in-focus image. What if the image was in focus?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pupil3 = NollZernike(samples=384, dia=25) # same parameters as before, but no error\n", "pupil3.phase += phase_mod\n", "\n", "pupil3.plot2d(clim=0.25) # +/- 138 nm\n", "plt.title('Wavefront with ripple error')\n", "\n", "ps = PSF.from_pupil(pupil3, efl=50, Q=3) # Q=2 now, we need high resolution\n", "ps.plot2d(xlim=20, power=1/4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This looks just like an Airy disk; the ripples have low RMS amplitude, so they do little damage to the in-focus image.\n", "\n", "What if the ripples were more localized, occuring in just one band within the clear aperture?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def gauss_r(r, center, sigma=0.1, amplitude=1):\n", " numerator = (r-center) ** 2\n", " denominator = 2 * sigma ** 2\n", " return amplitude * np.exp(-numerator / denominator)\n", " \n", "phase_mod2 = phase_mod * gauss_r(rho, center=0.66, sigma=0.02)\n", "phase_mod_vis = phase_mod2.copy()\n", "phase_mod_vis[pupil.transmission == 0] = np.nan\n", "plt.imshow(phase_mod_vis, cmap='inferno')\n", "\n", "pupil4 = pupil.copy()\n", "pupil4.phase += phase_mod2\n", "\n", "ps = PSF.from_pupil(pupil4, efl=50, Q=1.25) # Q=2 now, we need high resolution\n", "ps.plot2d(xlim=200, power=1/3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now there is an inner ring in addition to the Fresnel rings. The formation of this is related to the angular spectrum of the aperture. An ensemble of rays from the perturbed annulus of the aperture propagate at a different angle to the rest; the interference begins at the radius they appear at within the clear aperture, crosses through the center at focus where they overlap with the natural interference from the support of the aperture, then dissipate to an infinite distance as the observation plane moves further behind focus." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }